<?php
    // This is used to delete pages
    // INPUT: $_POST[]
    //
    // OUTPUT: Return text passed (encoded via htmlspecialchars)
    // SIDE EFFECT: Store _POST in database after authenticating user permissions


    require_once("../../../includes.php");
    require_once("../model/page.php");
    require_once("../redirect.php");
    require_once('../model/tags.php');

    if ( !isloggedin() ) {
        trigger_error('You mus be logged in to use this page', E_USER_ERROR);
    }

    // Load the response data that tells us what to do next.
    $redirect = folio_redirect::parse( $_POST );
    if( !$redirect ) {
        trigger_error('Redirect information not passed to page_update.php', E_USER_ERROR);
    }

    // Orienting data
    $page_ident = intval( required_param('page_ident' ) );

    $page = folio_page::SelectWherePageIdent( $page_ident );

    // Validate permissions
    if ( !$page->Permission('update')) {
        trigger_error('You do not have permission to delete this page', E_USER_ERROR);
    } else {
        // Delete page.
        $page->Delete();
    }

    // Perform the required redirect actions.
    //      This can send a header var to go to a new page, echo values, ...
    $redirect->PerformRedirectActions();

?>
